﻿using System;
using System.Globalization;
using ELearningSystem.UI.ContentServiceReference;
using ContentManager = ELearningSystem.UI.ContentServiceReference.ContentServiceSoapClient;
using AnswerManager = ELearningSystem.UI.AnswerServiceReference.AnswerServiceSoapClient;
using TreeContent = ELearningSystem.UI.ContentServiceReference.TreeContentDAO;

namespace ELearningSystem.UI.AdminUI
{
    public partial class AddContentUI : System.Web.UI.Page
    {
        ContentManager contentManager = new ContentManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                topicDropDownList.DataSource = contentManager.GetAllTopics();
                topicDropDownList.DataTextField = "Text";
                topicDropDownList.DataValueField = "Id";
                topicDropDownList.DataBind();

                positionTextBox.Text =
                    contentManager.GetLastPosition(contentManager.GetTreeContent(int.Parse(topicDropDownList.SelectedValue))).ToString();
            }
        }

        protected void nextLinkButton_Click(object sender, EventArgs e)
        {
            TreeContent treeContent = new TreeContent();
            treeContent.ParentNode = contentManager.GetTreeContent(int.Parse(topicDropDownList.SelectedValue));
            treeContent.Position = int.Parse(positionTextBox.Text);
            Session["Content"] = treeContent;
            if (videoRadioButton.Checked)
            {
                Response.Redirect("~/AdminUI/AddVideoUI.aspx");
            }
            if (practiceRadioButton.Checked)
            {
                Response.Redirect("~/AdminUI/AddPracticeUI.aspx");
            }
        }

        protected void topicDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            positionTextBox.Text =
              contentManager.GetLastPosition(contentManager.GetTreeContent(int.Parse(topicDropDownList.SelectedValue))).ToString(CultureInfo.InvariantCulture);
        }
    }
}